<?php

namespace App\Controller\My;


use App\Controller\BaseController;
use App\Exception\MessageException;
use App\Request\My\BindPhonePasswordRequest;
use App\Request\My\PhotoActionRequest;
use App\Request\My\UnreadMessageNumRequest;
use App\Request\My\videoActionRequest;
use App\Request\My\WantEvaluateRequest;
use App\Services\My\MyService;
use Hyperf\Context\Context;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;

class MyController extends BaseController
{
    #[Inject]
    public MyService $myService;


    /**
     * Note - 用户背包
     * DateTime 2024/8/8 15:26
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function backpack()
    {
        $userInfo = Context::get('user');
        $cardType = $this->request->post('card_type', 0);
        $language = Context::get('language');
        return $this->return($this->myService->backpack($userInfo, $cardType, $language));
    }


    /**
     * Note - 送礼收礼
     * DateTime 2024/8/8 18:49
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function receiveOrGiveGift()
    {
        $userInfo = Context::get('user');
        $userId = $this->request->post('user_id');
        return $this->return($this->myService->receiveOrGiveGift($userInfo, $userId));
    }


    /** Note - 个人中心
     * DateTime 2024/8/8 18:49
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function myInfo()
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        return $this->return($this->myService->myInfo($userInfo, $params));

    }


    /**
     * Note - 我的-视频管理接口（增删改）
     * DateTime 2024/8/9 14:24
     * User Admin
     */
    public function videoAction(VideoActionRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);
        $userInfo = Context::get('user');
        return $this->return($this->myService->videoAction($userInfo, $params));
    }


    /**
     * Note - 我的-照片管理接口（增删改查）
     * DateTime 2024/8/9 15:45
     * User Admin
     * @param PhotoActionRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function photoAction(PhotoActionRequest $request)
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        $request->execute($params);
        return $this->return($this->myService->photoAction($userInfo, $params));
    }


    /**
     * Note - 未读消息数量
     * DateTime 2024/8/15 11:40
     * User Admin
     */
    public function unreadMessageNum(UnreadMessageNumRequest $request)
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        $request->execute($params);
        return $this->return($this->myService->unreadMessageNum($userInfo, $params));

    }


    /**
     * Note - 用户绑定手机+绑定支付宝+设置密码+修改或重置
     * DateTime 2024/8/15 12:37
     * User Admin
     * @return ResponseInterface
     */
    public function bindPhonePassword(BindPhonePasswordRequest $request)
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        $type = $params['type'];
        $request->execute($params, $type);
        switch ($type) {
            case 1:
                // 绑定手机
                return $this->return($this->myService->bindPhone($userInfo['id'], $params));
            case 2:
                if ($userInfo['sex'] == 1) {
                    throw new MessageException('用户不支持该设置');
                }
                // 绑定支付宝
                return $this->return($this->myService->bindAlipay($userInfo['id'], $params));
            case 3:
                // 设置用户密码
                return $this->return($this->myService->setPassword($userInfo['id'], $params['password']));
            default:
                // 修改用户密码 忘记密码
                return $this->return($this->myService->modifyOrResetPassword($params));
        }
    }


    /**
     * Note - 头像修改
     * DateTime 2024/8/15 15:23
     * User Admin
     */
    public function headImageEdit()
    {
        $uid = Context::get('user')['id'];
        $image_url = $this->request->post('image_url', '');
        if (empty($image_url)) {
            throw new MessageException('头像不能为空');
        }
        $data = $this->myService->headImageEdit($uid, $image_url);
        return $this->return($data);

    }


    /**
     * Note - 设置用户喜欢的标签列表
     * DateTime 2024/9/3 16:14
     * User Admin
     * @param WantEvaluateRequest $request
     * @return ResponseInterface
     */
    public function wantEvaluate(WantEvaluateRequest $request)
    {
        $userInfo = Context::get('user');
        $params = $this->request->post();
        $request->execute($params);
        $result = $this->myService->wantEvaluate($userInfo, $params['ids']);
        return $this->return($result);
    }


}